#include "StdAfx.h"
#include "settings.h"

settings::settings(String^ myname)
{
	pathToFFmpeg="null";
	MyName=myname;
	readSett();
	writeSett();
}
void settings::readSett(void)
{
	String^ settFile=Path::Combine(MyName, "font.dll");
	if(File::Exists(settFile))
	{
		StreamReader^ readSettFile=gcnew StreamReader(settFile);
		Single sing=System::Convert::ToSingle(readSettFile->ReadLine());
		int still=System::Convert::ToInt32(readSettFile->ReadLine());
		FontStyle stil;
		if		(still==1) stil = FontStyle::Bold;
		else if(still==2) stil = FontStyle::Italic;
		else if(still==0) stil = FontStyle::Regular;
		else if(still==8) stil = FontStyle::Strikeout;
		else if(still==4) stil = FontStyle::Underline;
		String^ nameOfFont=readSettFile->ReadLine();
		System::Drawing::FontFamily ^fam=gcnew FontFamily(nameOfFont);
		Font^ ff = gcnew Font(fam, sing, stil);
		font_=ff;
		pathToFFmpeg=readSettFile->ReadLine();
		readSettFile->Close();
	}
	else
	{
		font_=gcnew Font("Monotype Corsiva", 15.75, FontStyle::Italic);
		pathToFFmpeg="NULL";
	} 
}
void settings::writeSett(void)
{
	String^ settFile=Path::Combine(MyName, "font.dll");
	String^ stroka="";
	String^ size;
	int style;
	StreamWriter^ writerOfFile=gcnew StreamWriter(settFile);
	
	writerOfFile->WriteLine(font_->Size.ToString());
	
	style = System::Convert::ToInt32(font_->Style);
	
	size=style.ToString();

	writerOfFile->WriteLine(size);
	if(System::String::IsNullOrEmpty(font_->OriginalFontName))writerOfFile->WriteLine(font_->Name);
	else writerOfFile->WriteLine(font_->OriginalFontName);
	//System::Windows::Forms::MessageBox::Show(font_->OriginalFontName);
	writerOfFile->WriteLine(pathToFFmpeg);
	writerOfFile->Close();
}




Font^ settings::GetFont(void)
{
	return font_;
}

String^ settings::GetFFmpegPath(void)
{
	return pathToFFmpeg;
}


void settings::SetFont(Font ^font__)
{
	font_=font__;
	writeSett();
}

void settings::SetFFmpegPath(String^ path_)
{
	this->pathToFFmpeg=path_;
}
